﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace SMS
{
    public partial class FQuanlytaikhoan : Form
    {
        fLogin main;
        public FQuanlytaikhoan(fLogin main1)
        {
            InitializeComponent();
            main = main1;
        }


        private DataTable show()
        {
            SqlDataAdapter da;
            DataTable dt = new DataTable();
            SqlConnection con = main.KetNoiDB.GetConServer();
            try
            {
                da = new SqlDataAdapter("SELECT MATK as 'Mã Tài Khoản',TENTK as 'Tên Tài Khoản',MATKHAUMD as 'Mật Khẩu' FROM TAIKHOAN Where TENTK like '%" + txtTuKhoa.Text.Trim() + "%' OR MATK like '%" + txtTuKhoa.Text.Trim() + "%'", con);
                dt.Clear();
                da.Fill(dt); // do ket qua truy van vao ban

            }
            catch (Exception ex)
            {
                MessageBox.Show("Lỗi!Xin thử lại" + ex.Message);
            }
            return dt;
        }
 
        private void bntVeGiaoDienChinh_Click_1(object sender, EventArgs e)
        {
            this.Visible = false;
            main.HeThong.Visible = true;
        }

        private void bntTaoTaiKhoanMoi_Click_1(object sender, EventArgs e)
        {
            panel1.Controls.Add(main.Themtaikhoan);
            main.Themtaikhoan.Show();
            main.Themtaikhoan.BringToFront();
            pictureBox1.Visible = false;
            //cboTukhoa.Enabled = false;
            txtTuKhoa.Enabled = false;
            cboTimKiemTheo.Enabled = false;
            bntTim.Enabled = false;
        }

        private void bntXemDanhSachTaiKhoan_Click_1(object sender, EventArgs e)
        {
            panel1.Controls.Add(main.Danhsachtaikhoan);
            main.Danhsachtaikhoan.Show();
            main.Danhsachtaikhoan.BringToFront();
            pictureBox1.Visible = false;
            cboTimKiemTheo.Enabled = true;
            txtTuKhoa.Enabled = true;
            bntTim.Enabled = true;
        }

        private void txtDangxuat_Click(object sender, EventArgs e)
        {
            this.Visible = false;
            main.Visible = true;
        }


        public void FQuanlytaikhoan_Load_1(object sender, EventArgs e)
        {
            main.Danhsachtaikhoan.Visible = false;
            main.Themtaikhoan.Visible = false;
            pictureBox1.Visible = true;
            cboTimKiemTheo.Enabled = false;
            txtTuKhoa.Enabled = false;
            bntTim.Enabled = false;

        }

        private void tsmiQuanLyKhachHang_Click_1(object sender, EventArgs e)
        {
            this.Visible = false;
            main.QuanLyKhachHang.Visible = true;
            main.QuanLyKhachHang.fQuanlykhachhang_Load(null, null);
        }

        private void tsmiQuanLyXe_Click_1(object sender, EventArgs e)
        {
            this.Visible = false;
            main.QuanLyXe.Visible = true;
            main.QuanLyXe.fQuanlyxe_Load(null,null);
        }

        private void tsmiQuanLyTinNhan_Click_1(object sender, EventArgs e)
        {
            this.Visible = false;
            main.QuanLyTinNhan.Visible = true;
            main.QuanLyTinNhan.fQuanlytinnhan_Load(null,null);
        }

        private void picExit_Click(object sender, EventArgs e)
        {
            this.Visible = false;
            main.Visible = true;
        }

        private void calculatorToolStripMenuItem_Click(object sender, EventArgs e)
        {
            System.Diagnostics.Process.Start("calc");
        }

        private void txtTuKhoa_TextChanged(object sender, EventArgs e)
        {
            SqlDataAdapter adapter;
            SqlConnection conn;
            SqlCommand command;
            DataTable dtbResult = new DataTable();
            conn = new SqlConnection(main.ConnectDB);
            command = new SqlCommand();
            command.Connection = conn;
            adapter = new SqlDataAdapter(command);

            command.CommandText = "SELECT MATK as 'Mã Tài Khoản',TENTK as 'Tên Tài Khoản',MATKHAUMD as 'Mật Khẩu' FROM TAIKHOAN where TENTK like'%'+ @ten +'%'";
            command.Parameters.Add(new SqlParameter("@ten", txtTuKhoa.Text.ToString()));

            try
            {

                adapter.Fill(dtbResult);
            }
            catch (Exception ex)
            {
                string err = ex.Message;
            }
            main.Danhsachtaikhoan.dataGridView1.DataSource = dtbResult;

            

        }

        private void bntTim_Click(object sender, EventArgs e)
        {
            main.Danhsachtaikhoan.dataGridView1.DataSource = show();
        }

        private void lnkDoiMatKau_Click(object sender, EventArgs e)
        {
            main.DoiMatKhau.ShowDialog();
        }

        private void aboutRestaurantSystemManagementToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                System.Diagnostics.Process prc = new System.Diagnostics.Process();
                string currentDir = Environment.CurrentDirectory;//lấy đường dẫn thư mục hiện tại.
                prc.StartInfo.FileName = currentDir + "\\PoD\\PoD.html";
                prc.Start();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Không thể mở file!");
            }
        }

        private void viewHelpToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                //Process k = new Process();
                //k.StartInfo.FileName = "C:\\Users\\PHUNGUYEN\\Desktop\\Year 3\\PM\\New folder\\SMS\\SMS\\PoD.doc";
                //k.StartInfo.Arguments = "";
                //k.Start();
                System.Diagnostics.Process prc = new System.Diagnostics.Process();
                string currentDir = Environment.CurrentDirectory;//lấy đường dẫn thư mục hiện tại.
                prc.StartInfo.FileName = currentDir + "\\PoD\\User Guide SMS_SYSTEM.pdf";
                prc.Start();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Không thể mở file!");
            }
        }

    }
}
